package com.qiahao.controller;

import com.qiahao.dto.PageDTO;
import com.qiahao.bean.Question;
import com.qiahao.service.QuestionService;
import com.qiahao.service.VoiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.util.Map;


@Controller
@RequestMapping("/question")
public class QuestionController {

    @Autowired
    QuestionService questionService;

    @Autowired
    VoiceService voiceService;

    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> addQuestion(HttpServletRequest request, Question question) {
        String path = request.getSession().getServletContext().getRealPath("voice/");
//        String path = "D:/";
        question.setPath(path);
        return questionService.addQuestion(question);
    }


    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    public PageDTO<Question> getQuestionList(Integer p, Integer step) {
        if (p == null) {
            p = 1;
        }
        if (step == null) {
            step = 10;
        }
        return questionService.findAllQuestion(p, step);
    }



}
